package com.zzyl.service.impl;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.AlertDataPageQueryDto;
import com.zzyl.mapper.AlertDataMapper;
import com.zzyl.service.AlertDataService;
import com.zzyl.vo.AlertDataVo;
import com.zzyl.vo.AlertRuleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class AlertDataServiceImpl implements AlertDataService {

    @Autowired
    private AlertDataMapper alertDataMapper;

    @Override
    public PageResponse<AlertDataVo> pageQuery(AlertDataPageQueryDto alertDataPageQueryDto) {
        PageHelper.startPage(alertDataPageQueryDto.getPageNum(), alertDataPageQueryDto.getPageSize());
        LocalDateTime start = null;
        LocalDateTime end = null;
        if(alertDataPageQueryDto.getEndTime() != null && alertDataPageQueryDto.getStartTime() != null){
            end = LocalDateTimeUtil.of(alertDataPageQueryDto.getEndTime());
            start = LocalDateTimeUtil.of(alertDataPageQueryDto.getStartTime());
        }
        Page<AlertDataVo> page = alertDataMapper.pageQuery(alertDataPageQueryDto, start, end);
        return PageResponse.of(page, AlertDataVo.class);
    }
}
